package com.sheep.jucdemo.part1.part1_6;

/**
 * @Date 2022/4/6 20:10
 * @Created by sheep
 */
public class Test1_6_1 implements Runnable{

    Test1_6_1(){
        Thread thread = new Thread(this);
        thread.start();
    }

    @Override
    public void run() {
        for (int i = 0; i < 5; i++) {
            if ((i % 5) == 0){
                System.out.println(Thread.currentThread() + "yield cpu...");
                // 当前线程让出CPU使用权，放弃时间片，进行下一轮调度
                Thread.yield();
            }


        }

        System.out.println(Thread.currentThread() + " is over");
    }

    public static void main(String[] args) {
        new Test1_6_1();
        new Test1_6_1();
        new Test1_6_1();
    }
}
